/***************************************************************
 * Name:      VBO.cpp
 * Purpose:   To handle grapich elements
 * Author:    Riku Maikola (rpm@ac-mapa.org)
 * Created:   2013-09-30
 * Copyright: Riku Maikola (rpm.ac-mapa.org)
 * License:
 **************************************************************/
 /*
#include <GL/glew.h>
#include <iostream>
#include <fstream>
#include <string>
#include "vbo.h"
#include "vmath.h"

#define BUFFER_OFFSET(i) ((void*)(i))


void VBO::Init()
{
    glewInit();
    Shader();
}


GLuint loadShader(const std::string filename,GLenum shaderType)
{
    GLuint shaderID = 0;
    std::string str;
    std::ifstream file(filename.c_str() ,  std::ios::in);
    if (file)
    {
        str.assign( ( std::istreambuf_iterator< char >( file ) ), std::istreambuf_iterator< char >() );
        shaderID = glCreateShader( shaderType );
        const GLchar* shaderSource = str.c_str();
        glShaderSource( shaderID, 1, (const GLchar**)&shaderSource, NULL );
        glCompileShader( shaderID );
        GLint shaderCompiled = GL_FALSE;
        glGetShaderiv( shaderID, GL_COMPILE_STATUS, &shaderCompiled );
        if( shaderCompiled != GL_TRUE )
        {
            printf( "Unable to compile shader %d!\n\nSource:\n%s\n", shaderID, shaderSource );
            glDeleteShader( shaderID );
            shaderID = 0;
        }
    }
    else
    {
        printf( "Unable to open file %s\n", filename.c_str() );
    }

    return shaderID;
}

void VBO::Shader()
{
    program = glCreateProgram();

    glAttachShader(program, loadShader("shader/vertex.shader",GL_VERTEX_SHADER));
    glAttachShader(program, loadShader("shader/fragment.shader",GL_FRAGMENT_SHADER));

    glLinkProgram(program);

    mv_location = glGetUniformLocation(program, "mv_matrix");
    view_location = glGetUniformLocation(program, "view_matrix");
    proj_location = glGetUniformLocation(program, "proj_matrix");
}

GLuint VBO::Create()
{
    GLuint VBO;

    float dta[] = {100,100,100,
                     0,  0,  0,
                   100,  0,  0,
                     1,  0,  0,
                     0,  0,  0,
                     0,  0,  0};

    glGenBuffers(1, &VBO);
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glBufferData(GL_ARRAY_BUFFER, sizeof(dta), dta, GL_STATIC_DRAW);

    glVertexAttribPointer(0, 3, GL_FLOAT , GL_FALSE , sizeof(float)*6, NULL); //vertex
    glVertexAttribPointer(1, 3, GL_FLOAT , GL_FALSE , sizeof(float)*6, BUFFER_OFFSET(12) ); //color
    glBindBuffer(GL_ARRAY_BUFFER, 0);



    return VBO;
};

void VBO::Render(GLuint vbo)
{
    if(vbo<1)return;

    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);

    //view_matrix = vmath::lookat( vmath::vec3(0,10,10 ),vmath::vec3(0,0,-9),vmath::vec3(0.0f, 1.0f, 0.0f));

    mv_matrix = vmath::translate(10.0f , 0.0f, 0.0f);

    glUseProgram(program);

    glUniformMatrix4fv(proj_location, 1, GL_FALSE, proj_matrix);
    glUniformMatrix4fv(view_location, 1, GL_FALSE, view_matrix);
    glUniformMatrix4fv(mv_location, 1, GL_FALSE, mv_matrix);


    glDrawArrays(GL_LINE_STRIP, 0, 3);
    glDisableVertexAttribArray(0);
    glDisableVertexAttribArray(1);

    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glUseProgram(0);

};
*/
